<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="${basePackage}.${moduleName}.mapper${submoduleName!?replace("\\", ".")}.${table.tableAlias}Mapper" >
	
	<sql id="${table.tableAlias}Columns">
		<#list table.primaryKeys as key>
		 	tt.${key.columnName} as ${key.javaProperty} 
		</#list>
		<#list table.baseColumns as column>
			,tt.${column.columnName} as ${column.javaProperty}
		</#list>
    </sql>
    
	<insert id="insert" flushCache="true" parameterType="${table.tableAlias}">
		insert into ${table.tableName} (
		<#list table.primaryKeys as key>
		 	${key.columnName}
		</#list>
		<#list table.baseColumns as column>
			<if test="${column.javaProperty} != null ">
			,${column.columnName}
			</if>
		</#list>
		) values (
		<#list table.primaryKeys as key>
		 	  ${r'#{'}${key.javaProperty}${r'}'} 
		</#list>
		<#list table.baseColumns as column>
			<if test="${column.javaProperty} != null ">
			,${r'#{'}${column.javaProperty}${r'}'} 
			</if>
		</#list>
		)
	</insert>
	
	<update id="update">
		update ${table.tableName} tt set 
			<#list table.primaryKeys as key>
			 	tt.${key.columnName} = ${r'#{'}${key.javaProperty}${r'}'} 
			</#list>
			<#list table.baseColumns as column>
			<if test="${column.javaProperty} != null ">
				,tt.${column.columnName} = ${r'#{'}${column.javaProperty}${r'}'} 
			</if>
			</#list>
			where
		    <#list table.primaryKeys as key>
			 	tt.${key.columnName} = ${r'#{'}${key.javaProperty}${r'}'} 
			</#list>
	</update>
	
	<delete id="delete" >
		delete from  ${table.tableName} tt 
		where 
		 <#list table.primaryKeys as key>
	 	tt.${key.columnName} = ${r'#{'}${key.javaProperty}${r'}'} 
		</#list>
	</delete>
	
	<select id="findByPk" resultType="${table.tableAlias}">
		select 
		<include refid="${table.tableAlias}Columns"/>
		from ${table.tableName} tt where 
		<#list table.primaryKeys as key>
		 	tt.${key.columnName} = ${r'#{'}${key.javaProperty}${r'}'} 
		</#list>
	</select>
	
	<select id="getList" resultType="${table.tableAlias}">
		select 
		<include refid="${table.tableAlias}Columns"/>
		from ${table.tableName} tt where 1=1
		<#list table.primaryKeys as key>
		 	<if test="${key.javaProperty} != null and ${key.javaProperty} != '' ">
			 	and tt.${key.columnName} = ${r'#{'}${key.javaProperty}${r'}'} 
			</if>
		</#list>
		<#list table.baseColumns as column>
			<if test="${column.javaProperty} != null and ${column.javaProperty} != '' ">
			 	and tt.${column.columnName} = ${r'#{'}${column.javaProperty}${r'}'} 
			</if>
		</#list>
		
	</select>
	
	<select id="getPage" resultType="${table.tableAlias}">
		select 
		<include refid="${table.tableAlias}Columns"/>
		from ${table.tableName} tt where 1=1
		<#list table.primaryKeys as key>
		 	<if test="bean.${key.javaProperty} != null and bean.${key.javaProperty} != '' ">
			 	and tt.${key.columnName} = ${r'#{bean.'}${key.javaProperty}${r'}'} 
			</if>
		</#list>
		<#list table.baseColumns as column>
			<if test="bean.${column.javaProperty} != null and bean.${column.javaProperty} != '' ">
			 	and tt.${column.columnName} = ${r'#{bean.'}${column.javaProperty}${r'}'} 
			</if>
		</#list>
		
	</select>
</mapper>